package com.study.constrollers;

import com.study.common.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * Created by bunny on 2017/8/21.
 */

@Controller
@RequestMapping("/dashboard")
public class IndexController {

    private static Logger logger = LoggerFactory.getLogger(IndexController.class);

    @RequestMapping("")
    public String index(HttpServletRequest request) {
        logger.info(request.getQueryString());

        request.setAttribute("name", request.getQueryString());

        return "dashboard";
    }

    @RequestMapping("/exception")
    public String name() {
        try {
            throw new RuntimeException("Hi, I'm error.");
        } catch (Exception ex) {
            logger.error(ex.getMessage());

            logger.error(ex.toString());
        }

        return "name";
    }
    /*@RequestMapping("/studenttest")
    public String (HttpServletRequest request, HttpServletResponse) {
        logger.info(request.getQueryString());

        request.setAttribute("name", request.getQueryString());

        return "/studenttest";*/

    @ResponseBody
    @RequestMapping("/json")
    public Message testJson() {
        return new Message();
    }

}
